//
//  LayoutConstraintTest.swift
//  SwiftUtils
//
//  Created by Ink on 2022/1/26.
//

import Foundation
import UIKit
import SnapKit

extension UIView {
    
    public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> Self {
        snp.makeConstraints(closure)
        return self
    }
    
    public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> Self {
        snp.remakeConstraints(closure)
        return self
    }
    
    public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> Self {
        snp.updateConstraints(closure)
        return self
    }
    
    public func removeConstraints() -> Self {
        snp.removeConstraints()
        return self
    }
}

class LayoutConstraintTest {
    
    class func execute(viewController: UIViewController) {
        
        let aView = UIView()
        aView.backgroundColor = .blue

        let bView = UIView()
        bView.backgroundColor = .red

        let cView = UIView()
        cView.backgroundColor = .yellow

        guard let view = viewController.view else { return }
        
        viewController.view.dsl.addSubviews {
            aView.dsl
                    .align(.top, to: view, 100)
                    .align(.left, to: view, 100)
                    .align(.right, to: view, -100)
                    .ratio()
                    .addSubviews {
                        cView.dsl
                            .align(.top, to: aView, 10)
                            .align(.left, to: aView, 10)
                            .align(.bottom, to: aView, -10)
                            .align(.right, to: aView, -10)
                    }
                bView.dsl
                    .margin(.top, to: aView, other: .bottom, 20)
                    .align(.left, to: aView)
                    .align(.right, to: aView)
                    .height(100)
                
        }
    }
}
